package com.example.sdk_test_demo;

import android.app.base.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;

import com.mchsdk.open.MCApiFactory;

/**
 * Created by Administrator on 2017/6/13.
 * 查看log， Activity
 */

public class ShowLogActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        if (Build.VERSION.SDK_INT >= 23) {
//            if (!Settings.canDrawOverlays(activity)) {
//                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
//                activity.startActivityForResult(intent, 1);
////                finish();
//                return;
//            } else {
//                MCApiFactory.getMCApi().showLog(ShowLogActivity.this, new String[]{"SDK4.0"});
//            }
//        } else {
//            MCApiFactory.getMCApi().showLog(ShowLogActivity.this, new String[]{"SDK4.0"});
//        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        MCApiFactory.getMCApi().showLog(ShowLogActivity.this,new String[]{"SDK4.0"});
    }

    @Override
    protected void onPause() {
        super.onPause();
        MCApiFactory.getMCApi().hideLog(ShowLogActivity.this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MCApiFactory.getMCApi().stopService();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (100 == requestCode) {
            if (Build.VERSION.SDK_INT >24) {
                if (!Settings.canDrawOverlays(activity)) {
                    Toast.makeText(this, "限制后将无法查看log", Toast.LENGTH_LONG).show();
                    finish();
                } else {
                    MCApiFactory.getMCApi().showLog(ShowLogActivity.this, new String[]{"SDK4.0"});
                }
            }
        }
    }
}
